package com.xy.xylive.common;

import org.bouncycastle.crypto.digests.SM3Digest;

public class SM3Util {
    //使用SM3进行加密
    public static String encrypt(String data) {
        byte[] dataBytes = data.getBytes();
        SM3Digest digest = new SM3Digest();
        digest.update(dataBytes, 0, dataBytes.length);
        byte[] result = new byte[digest.getDigestSize()];
        digest.doFinal(result, 0);
        return bytesToHex(result);
    }

    // 将字节数组转换为十六进制字符串
    public static String bytesToHex(byte[] bytes) {
        StringBuilder sb = new StringBuilder();
        for (byte b : bytes) {
            sb.append(String.format("%02X", b));
        }
        return sb.toString();
    }
}
